package com.eonmind.ai.controller;

import com.eonmind.ai.dto.AiVideoDto;
import com.eonmind.ai.service.impl.AiBiService;
import com.eonmind.ai.service.impl.AiVideoService;
import com.eonmind.common.contract.data.response.PageResponse;
import com.eonmind.common.contract.data.response.ResponseEntity;
import com.eonmind.common.security.annotations.UserInfo;
import com.eonmind.user.contract.dto.UserInfoData;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * AI视频
 */
@RestController
public class AiVideoController {
    @Resource
    private AiVideoService aiVideoService;
    @Autowired
    private AiBiService aiBiService;

    /**
     * 提交Pixverse 视频任务
     *
     * @param aiVideoTaskSubmitRequest 视频任务提交请求
     * @return
     * @ignoreParams userInfoData
     */
    @UserInfo
    @PostMapping("/ai/video/pixverse/submit")
    public ResponseEntity<AiVideoDto.AiVideoTaskSubmitResponse> submitVideoTask(
            UserInfoData userInfoData,
            @RequestBody @Validated AiVideoDto.PixverseTaskSubmitRequest aiVideoTaskSubmitRequest) {
        AiVideoDto.AiVideoTaskSubmitResponse aiVideoTaskSubmitResponse
                = aiVideoService.submitVideoTask(userInfoData, aiVideoTaskSubmitRequest);
        aiBiService.updateUserConsumeHistory(userInfoData.getId(), 0L, 0L, 1L, "");
        return ResponseEntity.success(aiVideoTaskSubmitResponse);
    }

    /**
     * 查询Pixverse 视频任务结果
     *
     * @param aiVideoTaskQueryRequest
     * @return
     * @ignoreParams userInfoData
     */
    @UserInfo
    @PostMapping("/ai/video/pixverse/query")
    public ResponseEntity<AiVideoDto.VideoTaskQueryResponse> queryVideoTask(
            UserInfoData userInfoData,
            @RequestBody @Validated AiVideoDto.PixverseTaskQueryRequest aiVideoTaskQueryRequest) {
        AiVideoDto.VideoTaskQueryResponse aiVideoTaskQueryResponse
                = aiVideoService.queryVideoTask(userInfoData, aiVideoTaskQueryRequest);
        return ResponseEntity.success(aiVideoTaskQueryResponse);
    }

    /**
     * 分页查询用户视频任务结果
     *
     * @param aiVideoTaskPageQueryRequest
     * @return
     * @ignoreParams userInfoData
     */
    @UserInfo
    @PostMapping("/ai/video/page")
    public ResponseEntity<PageResponse<AiVideoDto.VideoTaskQueryResponse>>
    page(UserInfoData userInfoData,
         @RequestBody AiVideoDto.VideoTaskPageQueryResponse aiVideoTaskPageQueryRequest) {
        PageResponse<AiVideoDto.VideoTaskQueryResponse> aiVideoTaskPageQueryResponse
                = aiVideoService.pageVideoTask(userInfoData, aiVideoTaskPageQueryRequest);
        return ResponseEntity.success(aiVideoTaskPageQueryResponse);
    }
}
